package com.xuerhua.yxt.controller.teacher;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xuerhua.yxt.common.Const;
import com.xuerhua.yxt.common.MenuConst;
import com.xuerhua.yxt.controller.BaseController;
import com.xuerhua.yxt.model.TeacherInfo;
import com.xuerhua.yxt.reqVo.ScoreSummaryQueryVO;
import com.xuerhua.yxt.reqVo.TeacherReqVO;
import com.xuerhua.yxt.service.IScoreSummaryService;
import com.xuerhua.yxt.service.ITeacherFruitsService;
import com.xuerhua.yxt.service.ITeacherService;
import com.xuerhua.yxt.utils.BeanUtils;
import com.xuerhua.yxt.view.TeacherInfoView;

@RequestMapping(Const.TEACHER_ROLE + MenuConst.TEACHING_FRUIT_REPORT)
@Controller
public class TeachingFruitReportController extends BaseController{

	private Logger logger = LoggerFactory.getLogger(TeachingFruitReportController.class);
	
	@Autowired
	private ITeacherService teacherService;
	@Autowired
	private IScoreSummaryService scoreSummaryService;
	@Autowired
	private ITeacherFruitsService teacherFruitsService;
	
	@RequestMapping(value={"","/"})
	public String list() {
		return "teacher/teachingFruitReport/list";
	}
	
	@RequestMapping("detail/{teacherId}")
	public String detail(Model model, @PathVariable Integer teacherId) {
		TeacherInfo teacher = teacherService.selectById(teacherId);
		if(teacher == null) return null;
		model.addAttribute("teacher", BeanUtils.copyAs(teacher, TeacherInfoView.class));
		return "teacher/teachingFruitReport/detail";
	}
	
	@RequestMapping("teacherList")
	@ResponseBody Object teacherList(TeacherReqVO vo) {
		try {
			vo.setFinishYear(getCurrentTerm().getFinishYear());
			vo.setSchoolId(getAppUser().getTeacher().getSchoolId());
			List<TeacherInfo> list = teacherService.selectListForMainSubject(vo);
			return BeanUtils.copyAs(list, TeacherInfoView.class);
		} catch (Exception e) {
			logger.error("--teacherList error={}", e);
		}
		return null;
	}
	
	@RequestMapping("scoreSummary/list")
	@ResponseBody Object scoreSummaryList(ScoreSummaryQueryVO vo) {
		try {
			vo.setSchoolId(getAppUser().getTeacher().getSchoolId());
			return scoreSummaryService.selectScoreSummaryList(vo);
		} catch (Exception e) {
			logger.error("--scoreSummaryList error={}", e);
		}
		return null;
	}
	
	@RequestMapping("prizeList")
	@ResponseBody Object prizeList(ScoreSummaryQueryVO vo) {
		try {
			vo.setSchoolId(getAppUser().getTeacher().getSchoolId());
			return teacherFruitsService.selectListByParam(vo);
		} catch (Exception e) {
			logger.error("--prizeList error={}", e);
		}
		return null;
	}
}
